﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using Portal.Systems.Model;
using Portal.Database.Service;
using Portal.Web.Utility;
using Portal.Core;
using Portal.Systems.Bussiness.Template;

namespace Portal.Systems.Bussiness
{
    public class AssetProcessBll
    {
        public static AssetCls[] ReadingAssets(string SiteId)
        {
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            IDatabaseService DBService = WebDatabaseService.CreateDBService(SiteId);
            string Query =
                "select * from TableAsset order by AssetCode";
            DataSet dsResult =
                    DBService.GetDataSet(null, Query,null);
            if (dsResult.Tables[0].Rows.Count == 0)
            {
                return new AssetCls[0];
            }
            AssetCls[] Assets = AssetParser.ParseFromDataTable(dsResult.Tables[0]);
            dsResult.Clear();
            dsResult.Dispose();
            return Assets;
        }

        public static AssetCls CreateAssetModel(string SiteId, string AssetCode)
        {
            IDatabaseService DBService = WebDatabaseService.CreateDBService(SiteId);
            DataSet dsResult =
                    DBService.GetDataSet(null, "select * from TableAsset where AssetCode=@AssetCode",
                    new DbParam[] 
                    { 
                        new DbParam("AssetCode", AssetCode),
                    });
            if (dsResult.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            AssetCls OAsset = AssetParser.ParseFromDataRow(dsResult.Tables[0].Rows[0]);
            dsResult.Clear();
            dsResult.Dispose();
            return OAsset;
        }
    }
}

